#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
queue<int> Q;
int first, last;
int visit[2 * MAXN];

int main() {
  memset(visit, -1, sizeof(visit));
  cin >> first >> last;

  Q.push(first);
  visit[first] = 0;

  while (!Q.empty()) {
    int s = Q.front();
    Q.pop();
    int step = visit[s];
    if (s == last) {
      cout << step;
      break;
    }
    int new1 = s + 1, new2 = s - 1, new3 = 2 * s;

    if (new1 <= MAXN + 10 && visit[new1] == -1) {
      Q.push(new1);
      visit[new1] = step + 1;
    }
    if (new2 >= 0 && visit[new2] == -1) {
      Q.push(new2);
      visit[new2] = step + 1;
    }
    if (new3 <= MAXN + 10 && visit[new3] == -1) {
      Q.push(new3);
      visit[new3] = step + 1;
    }
  }

  return 0;
}